<template>
  <el-dialog
    title="选择课程类型"
    :visible.sync="visible"
    :close-on-click-modal="false"
    :width="dialogWidth"
    center
    @close="handleClose"
  >
    <div class="dialog-content-wrapper">
      <div class="course-type-grid">
        <div
          v-for="(course, index) in courseTypes"
          :key="index"
          class="course-type-card"
          @click="handleCourseSelect(course)"
        >
          <div class="course-icon" v-html="course.icon"/>
          <div class="course-name">{{ course.name }}</div>
        </div>
      </div>
    </div>
  </el-dialog>
</template>

<script>
export default {
  name: 'CourseTypeDialog',
  props: {
    visible: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      courseTypes: [
        { name: '词汇', icon: '<i class="fas fa-book"></i>' },
        { name: '语法', icon: '<i class="fas fa-code"></i>' },
        { name: '阅读', icon: '<i class="fas fa-newspaper"></i>' },
        { name: '写作', icon: '<i class="fas fa-pen"></i>' },
        { name: '听力', icon: '<i class="fas fa-headphones"></i>' }
      ]
    }
  },
  computed: {
    // 根据屏幕宽度动态调整对话框宽度
    dialogWidth() {
      const screenWidth = window.innerWidth
      if (screenWidth < 768) {
        return '90%'
      } else if (screenWidth < 1200) {
        return '70%'
      } else {
        return '1000px' // 大屏幕固定最大宽度
      }
    }
  },
  methods: {
    handleCourseSelect(course) {
      this.$emit('selectWordCourse', course.name)
    },
    handleClose() {
      this.$emit('close')
    }
  }
}
</script>

<style scoped>
.dialog-content-wrapper {
  display: flex;
  justify-content: center;
  padding: 15px 0;
}

.course-type-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 25px;
  width: 100%;
  max-width: 1000px; /* 限制内容最大宽度 */
}

.course-type-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 25px 15px;
  border-radius: 12px;
  border: 1px solid #e5e7eb;
  cursor: pointer;
  transition: all 0.3s ease;
  text-align: center;
  min-height: 160px; /* 确保卡片高度一致 */
  justify-content: center;
  background-color: #fff;
}

.course-type-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 10px 20px rgba(0, 132, 255, 0.15);
  border-color: #0084ff;
  background-color: rgba(0, 132, 255, 0.03);
}

.course-icon {
  font-size: 32px;
  margin-bottom: 15px;
  color: #0084ff;
  transition: transform 0.3s ease;
}

.course-type-card:hover .course-icon {
  transform: scale(1.1);
}

.course-name {
  font-size: 17px;
  font-weight: 500;
  color: #333;
}

/* 针对大屏幕的额外优化 */
@media screen and (min-width: 1200px) {
  .el-dialog {
    max-width: 1000px !important;
  }
}

/* 小屏幕适配 */
@media screen and (max-width: 576px) {
  .course-type-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 15px;
  }

  .course-type-card {
    padding: 20px 10px;
    min-height: 140px;
  }

  .course-icon {
    font-size: 28px;
  }
}
</style>
